package com.livedocumentation.client.webservices.project;

import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.json.client.JSONObject;
import com.google.gwt.jsonp.client.JsonpRequestBuilder;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.livedocumentation.client.GWTEntryPoint;
import com.livedocumentation.client.model.Project;

public class RequestGetProjectRepository {

	private static String url = "http://jsonpfy.livesourceagile.appspot.com/GetDataService";

	public static void getJsonpRequest(final String projectID,
			final String classPath) {

		JsonpRequestBuilder jsonp = new JsonpRequestBuilder();

		jsonp.setTimeout(10000);

		String urlGet = url + "?kind=Project&ID=" + projectID;

		jsonp.requestObject(urlGet, new AsyncCallback<JavaScriptObject>() {

			public void onFailure(Throwable throwable) {

				System.out.println("Error: " + throwable);
			}

			public void onSuccess(JavaScriptObject feed) {

				JSONObject entry = new JSONObject(feed);

				Project project = ConvertJsonpToProject
						.convertJsonProject(entry);

				GWTEntryPoint.currentProject = project;

				RequestGetProjectInfo.getJsonpRequest(projectID, classPath);
			}
		});
	}
}
